import request from "../request";
import qs from "qs";
interface productCategoryData {
  pageNum?: number;
  pageSize?: number;
  parentId?: number;
}
//商品分类返回值
interface CategoryData {
  pageNum: number;
  pageSize: number;
  totalPage: number;
  total: number;
  list: CategoryList[];
}
interface CategoryList {
  id: number;
  parentId: number;
  name: string;
  level?: number;
  productCount?: number;
  productUnit: string;
  navStatus: number;
  showStatus: number;
  sort: number;
  icon?: string;
  keywords: string;
  description?: string;
  productAttributeIdList: number | Array<number>;
}

//获取所有商品属性分类及其下属性
interface withAttrRef {
  id: number;
  name: string;
  attributeCount?: any;
  paramCount?: any;
  productAttributeList: ProductAttributeList[];
}
interface ProductAttributeList {
  id: number;
  productAttributeCategoryId?: any;
  name: string;
  selectType?: any;
  inputType?: any;
  inputList?: any;
  sort?: any;
  filterType?: any;
  searchType?: any;
  relatedStatus?: any;
  handAddStatus?: any;
  type?: any;
}
//添加商品
interface createRef {
  description: string;
  icon: string;
  keywords: string;
  name: string;
  navStatus: number;
  parentId: number;
  productUnit: string;
  showStatus: number;
  sort: number;
  productAttributeIdList: number | Array<number>;
}
//查询商品属性params
interface productAttributeRef {
  cid: number;
  pageNum?: number;
  pageSize?: number;
  type: number;
}
//商品分类/mall-admin/productCategory/list/{parentId}
const productCategoryAPI = (
  params?: productCategoryData
): Promise<CategoryData> =>
  request.get(`/productCategory/list/${params?.parentId}`, { params });
//mall-admin/Abcdeioprrttttuu / category / list / withAttr;获取所有商品属性分类及其下属性;
const withAttrAPI = (): Promise<withAttrRef[]> =>
  request.get("/productAttribute/category/list/withAttr");
///mall-admin/productCategory/update/navStatus修改导航栏显示状态
const navStatusAPI = (data: { ids: number; navStatus: number }) =>
  request.post("/productCategory/update/navStatus", qs.stringify(data));
const showStatusAPI = (data: { ids: number; showStatus: number }) =>
  request.post("/productCategory/update/showStatus", qs.stringify(data));
///mall-admin/productCategory/delete/{id}删除商品分类
const deleteAPI = (data: number) =>
  request.post(`/productCategory/delete/${data}`);
///mall-admin/productCategory/create添加产品分类
const createAPI = (params: createRef) =>
  request.post("/productCategory/create", params);
///mall-admin/productCategory/update/{id}修改商品分类
const changeCommodity = (params: CategoryList) =>
  request.post(`/productCategory/update/${params.id}`, params);
///mall-admin/productCategory/{id}根据id获取商品分类;
const getGoodsCategory = (data: number): Promise<CategoryList> =>
  request.get(`/productCategory/${data}`);
//属性管理
///mall-admin/productAttribute/category/list分页获取所有商品属性分类
const categoryListAPI = (params?: productCategoryData) =>
  request.get("/productAttribute/category/list", { params });
///productAttribute/category/create添加商品属性分类
const addCategoryAPI = (params: { name: string }) =>
  request.post("/productAttribute/category/create", qs.stringify(params));
///productAttribute/list/{cid}根据分类查询属性列表或参数列表
const productAttributeAPI = (params: productAttributeRef) =>
  request.get(`/productAttribute/list/${params.cid}`, params as any);
export {
  productCategoryAPI,
  withAttrAPI,
  navStatusAPI,
  showStatusAPI,
  deleteAPI,
  createAPI,
  changeCommodity,
  getGoodsCategory,
  categoryListAPI,
  addCategoryAPI,
  productAttributeAPI,
};
